package org.csu.small.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.csu.small.common.Constant;
import org.csu.small.common.UniformResponse;
import org.csu.small.entity.Order;
import org.csu.small.entity.Product;
import org.csu.small.entity.User;
import org.csu.small.persistence.OrderMapper;
import org.csu.small.persistence.ProductMapper;
import org.csu.small.persistence.UserMapper;
import org.csu.small.service.IStatisticService;
import org.csu.small.vo.StatisticVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Rambo
 * @date 2020-07-08 16:02
 */
@Service
public class StatisticServiceImpl implements IStatisticService {
    @Autowired
    private UserMapper userMapper;

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public UniformResponse<StatisticVO> getBaseCount() {
        Integer userCount = userMapper.selectCount(Wrappers.<User>query().eq("role", Constant.Role.CUSTOMER));
        Integer productCount = productMapper.selectCount(Wrappers.<Product>query());
        Integer orderCount = orderMapper.selectCount(Wrappers.<Order>query());
        StatisticVO statistic = new StatisticVO(userCount, productCount, orderCount);
        return UniformResponse.createForSuccess(statistic);
    }
}
